class NasController < ApplicationController
  before_action :set_nas, only: [:show, :edit, :update, :destroy]

  # GET /nas
  # GET /nas.json
  def index
    @nas = current_account.nas.all
  end

  # GET /nas/1
  # GET /nas/1.json
  def show
  end

  # GET /nas/new
  def new
    @nas = current_account.nas.new
  end

  # GET /nas/1/edit
  def edit
  end

  # POST /nas
  # POST /nas.json
  def create
    @nas = Nas.new(nas_params)
    @nas.account = current_account

    respond_to do |format|
      if @nas.save
        format.html { redirect_to @nas, notice: 'Nas was successfully created.' }
        format.json { render action: 'show', status: :created, location: @nas }
      else
        format.html { render action: 'new' }
        format.json { render json: @nas.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /nas/1
  # PATCH/PUT /nas/1.json
  def update
    respond_to do |format|
      if @nas.update(nas_params)
        format.html { redirect_to @nas, notice: 'Nas was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @nas.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /nas/1
  # DELETE /nas/1.json
  def destroy
    @nas.destroy
    respond_to do |format|
      format.html { redirect_to nas_index_url }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_nas
      @nas = current_account.nas.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def nas_params
      params.require(:nas).permit(:nasname, :shortname, :types, :ports, :secret, :server, :community, :description)
    end
end
